package com.snail.snailvr.mvp.presenter;

import com.snail.snailvr.model.BannerModel;
import com.snail.snailvr.mvp.views.BaseView;
import com.snail.snailvr.network.VRApi;
import com.snail.snailvr.utils.NetworkUtil;

import java.lang.ref.WeakReference;

/**
 * Created by snail on 16/6/30.
 */

public class DiscoverPresenter extends Presenter {
    private WeakReference<BaseView> mBaseViewWeakReference;
    public DiscoverPresenter(BaseView baseView){
        mBaseViewWeakReference=new WeakReference<>(baseView);
    }

    @Override
    public BaseView getMvpView() {
        return mBaseViewWeakReference.get();
    }

    @Override
    public void success(Object result) {
        if (result instanceof BannerModel) {
            mBaseViewWeakReference.get().onRequestComplete((BannerModel)result);
        }
    }

    @Override
    public void loadData() {
        if (NetworkUtil.isNetworkConnected()) {
            VRApi.getBanner(this);
        } else {
            getMvpView().showError();
        }

    }
}
